package com.fengli.task.dao;

import com.fengli.task.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 插入用于
     * @param userEntity
     */
    @Insert("insert into user(id,email,password,head_picture,del) values(#{id},#{email},#{password},#{headPicture},0)")
    void insert(UserEntity userEntity);

    /**
     * （究极更新方法！）<br>
     * 更新用户，对应的userEntity的属性不为空，就更新相应字段
     * @param userEntity
     */
    void update(@Param("user") UserEntity userEntity);

    /**
     * 根据email,password查询用户（未注销的）
     * @param email
     * @param password
     * @return
     */
    @Select("select * from user where email = #{email} and password = #{password} and del =  0")
    UserEntity queryUser(@Param("email") String email, @Param("password") String password);

    /**
     * 根据email查询用户（未注销的）
     * @param email
     * @return
     */
    @Select("select * from user where email = #{email} and del =  0")
    UserEntity queryUserByEmail(@Param("email") String email);

    /**
     * 根据id查询用户（未注销的）
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id} and del = 0")
    UserEntity queryUserById(@Param("id") String id);

    /**
     * 究极查询方法（对应userEntity的属性不为空，就是一个查询条件）<br>
     * 需要注意，查询结果可能不只一条
     * @param userEntity
     * @return
     */
    List<UserEntity> queryUserList(@Param("user") UserEntity userEntity);

}
